package FactoryMethod.cashier;

/**
 * @author duanzhizhou
 * @date 2024/9/26
 */
public class ReduceCashier extends CashDecorator {
    
    private final double ret;
    
    private final double cond;
    
    public ReduceCashier(Cashier cashier, double cond, double ret) {
        super(cashier);
        this.ret = ret;
        this.cond = cond;
    }
    
    @Override
    public double check(double price, int cnt) {
        double total = super.check(price, cnt);
        if (cond > 0 && ret > 0) {
            total = total == 0d ? price * cnt : total;
            return total - Math.floor(total / cond) * ret;
        }
        return total;
    }
}
